package com.manong.bookstore.order.service.impl;

import com.alibaba.nacos.client.utils.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manong.common.utils.PageUtils;
import com.manong.common.utils.Query;

import com.manong.bookstore.order.dao.OrderDetailDao;
import com.manong.bookstore.order.entity.OrderDetailEntity;
import com.manong.bookstore.order.service.OrderDetailService;


@Service("orderDetailService")
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailDao, OrderDetailEntity> implements OrderDetailService {

//    @Override
//    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<OrderDetailEntity> page = this.page(
//                new Query<OrderDetailEntity>().getPage(params),
//                new QueryWrapper<OrderDetailEntity>()
//        );
//
//        return new PageUtils(page);
//    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //1、获取key
        String key = (String) params.get("key");
        QueryWrapper<OrderDetailEntity> queryWrapper = new QueryWrapper<>();

        if(!StringUtils.isEmpty(key)){
            queryWrapper.eq("order_detail_id",key)
                    .or().eq("order_id",key)
                    .or().eq("produce_id",key)
                    .or().eq("produce_price",key)
                    .or().like("produce_name",key);
        }

        IPage<OrderDetailEntity> page = this.page(
                new Query<OrderDetailEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }


    @Override
    public PageUtils queryPage(Map<String, Object> params, Integer orderId) {
        QueryWrapper<OrderDetailEntity> wrapper=new QueryWrapper<OrderDetailEntity>().eq("order_id",orderId);
        IPage<OrderDetailEntity> page=this.page(new Query<OrderDetailEntity>().getPage(params),wrapper);
        return new PageUtils(page);
    }

}